home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig20_32.jar / Ch20 / Fig20_32 / fig20_32.cpp
C/C++ Source or Header  |  1997-10-22  |  885b  |  35 lines

  1. // Fig. 20.32: fig20_32.cpp
  2. // Demonstrates iter_swap, swap and swap_ranges.
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.    const int SIZE = 10;
  11.    int a[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  12.    ostream_iterator< int > output( cout, " " );
  13.  
  14.    cout << "Array a contains:\n";
  15.    copy( a, a + SIZE, output );
  16.  
  17.    swap( a[ 0 ], a[ 1 ] );
  18.    cout << "\nArray a after swapping a[0] and a[1] "
  19.         << "using swap:\n";
  20.    copy( a, a + SIZE, output );
  21.  
  22.    iter_swap( &a[ 0 ], &a[ 1 ] );
  23.    cout << "\nArray a after swapping a[0] and a[1] "
  24.         << "using iter_swap:\n";
  25.    copy( a, a + SIZE, output );
  26.  
  27.    swap_ranges( a, a + 5, a + 5 );
  28.    cout << "\nArray a after swapping the first five elements\n"
  29.         << "with the last five elements:\n";
  30.    copy( a, a + SIZE, output );
  31.  
  32.    cout << endl;
  33.    return 0;
  34. }
  35.